<%@page import="Tools.ConvertUnixTime"%>
<%@page import="Entity.Category"%>
<%@page import="DAO.DAO_Category"%>
<%@page import="java.util.StringTokenizer"%>
<%@page import="org.jsoup.Jsoup"%>
<%@page import="Entity.News"%>
<%@page import="java.util.List"%>
<%@page import="java.util.List"%>
<%@page import="DAO.DAO_News"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="includes/masterHeader.jsp" %>

<div class="container-fluid">
    <%@ include file="includes/masterSidebarLeft.jsp" %>
  
  <!--center-->
  <div class="col-sm-6">
<%
    DAO_News daonews = new DAO_News();
    String search_term = request.getParameter("search-term");
    
    String c = request.getParameter("c");
    
    List <News>latestNews = null;
    
    if(search_term != null && !search_term.isEmpty()) {
        search_term = new String(search_term.getBytes("ISO8859_1"), "UTF-8");
        latestNews = daonews.searchNews(search_term);
    }else if(c != null && !c.isEmpty()) {
        latestNews = daonews.newsInCat(c);
    }else {
        latestNews = daonews.newsList();
    }
    
    for(News anArticle : latestNews) {
        %>
    <div class="row">
      <div class="col-xs-12">
        <h2><a href="Threads.jsp?s=<%=anArticle.getSlug()%>"><%=anArticle.getTitle()%></a></h2>
        <p>
        <%
        String in = Jsoup.parse(anArticle.getContent()).text();
        in = in.substring(0, Math.min(in.length(), 255))+ "...";
        out.print(in);
        %></p>
        <p class="pull-right">
            <%
                String tags = anArticle.getTags();
                if(tags.length() > 0) {
                    StringTokenizer st = new StringTokenizer(tags, ",");
                    while(st.hasMoreTokens()) {
                        out.print("<span class=\"label label-default\" style=\"margin-right: 5px;\">"+ st.nextToken() +"</span>");
                    }
                }
            %>
            
        </p>
        <ul class="list-inline"><li><a href="#"><i class="glyphicon glyphicon-user"></i><%=anArticle.getAuthor()%></a></li><li><a href="#"><i class="glyphicon glyphicon-calendar"></i><%=ConvertUnixTime.normalTime(anArticle.getDateline())%></a></li></ul>
      </div>
    </div>
    <hr>
        <%
        daonews.closeConnection();
    }
%>

  </div><!--/center-->

<%@ include file="includes/masterSidebarRight.jsp" %>
  <hr>
</div><!--/container-fluid-->
<%@ include file="includes/masterFooter.jsp" %>